Manage employees
UserManager
Manage employees.
class yandex_b2b_go.user.UserManager(client: Client)
Attribute
-
SpendingManager — detailed employee expenses.
spending: SpendingManager
Methods
- create — creates an employee.
- list — gets a list of employees.
- get — receives detailed information about the client's employee.
- update — updates information about the client's employee.
- archive — archives the client's employee.
Create
Creates an employee.
async def create(user: User) -> UserCreateResponse
Parameter
user– data about a new employee. Class User.
If successful, returns the UserCreateResponse class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import UserManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
user_manager = UserManager(client=client)
try:
user = typing.User(
fullname='Ilya Ivanov',
phone='+79990000000',
is_active=True,
nickname='Ilya',
cost_centers_id='123...fef',
department_id='987...ghj',
limits=[
typing.Limit(
limit_id='abcdef_taxi',
service=typing.Service('taxi')
),
typing.Limit(
limit_id='abcdef_eats',
service=typing.Service('eats')
),
typing.Limit(
limit_id='abcdef_drive',
service=typing.Service('drive')
),
],
)
response_create = await user_manager.create(user=user)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
List
Gets a list of employees.
async def list(
limit: Optional[int] = None,
cursor: Optional[str] = None
) -> UserListResponse
Parameters
limit— number of records to display. If this parameter is not specified, information about the first 100 records is returned.cursor— request marker (returned in the body of response to the previous request). The parameter is not required for the first page, but is required for subsequent pages.
If successful, the UserListResponse class is returned.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import UserManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
user_manager = UserManager(client=client)
try:
users_list = await user_manager.list(limit=100, offset=0)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
Get
Gets detailed information about the client's employee.
async def get(user_id: str) -> UserGetResponse
Parameter
user_id— employee ID to provide information about.
If successful, returns the UserGetResponse class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import UserManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
user_manager = UserManager(client=client)
try:
user_info = await user_manager.get(user_id='f65...c57d')
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
Update
Updates information about the client's employee.
async def update(
user_id: str,
user: User
) -> UserUpdateResponse
Parameter
user_id— employee ID used when updating information.user– employee data, class User.
If successful, the UserUpdateResponse class is returned.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import UserManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
user_manager = UserManager(client=client)
try:
user = typing.User(
fullname='Ilya Ivanov',
phone='+79990000000',
is_active=True,
nickname='Ilya',
cost_centers_id='123...fef',
department_id='987...ghj',
limits=[
typing.Limit(
limit_id='abcdef_taxi',
service=typing.Service('taxi')
),
typing.Limit(
limit_id='abcdef_eats',
service=typing.Service('eats')
),
typing.Limit(
limit_id='abcdef_drive',
service=typing.Service('drive')
),
],
)
response_update = await user_manager.update(user_id='f65...c57d', user=user)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
Archive
Archives the client's employee.
async def archive(user_id: str) -> UserUpdateResponse
Parameter
user_id– employee ID whose data is being archived.
If successful, the UserUpdateResponse class is returned.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import UserManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
user_manager = UserManager(client=client)
try:
response_archive = await user_manager.archive(user_id='f65...c57d')
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())
SpendingManager
Employee expense details.
class yandex_b2b_go.user.SpendingManager(client: Client)
Method
- list — shows the details of employee expenses within their limits.
List
Shows the details of employee expenses within their limits.
async def list(user_ids: UsersSpendingListRequest) -> UsersSpendingListResponse
Parameter
user_ids: list of employees to request expense details for, class UsersSpendingListRequest.
If successful, returns the UserSpendingListResponse class.
If the parameters are incorrect, the method returns the ValidationError error.
If the response code is not 200, an error is returned: ApiError.
Request example
import asyncio
from yandex_b2b_go import Client
from yandex_b2b_go import UserManager
from yandex_b2b_go import typing, errors
TOKEN = '<your token>'
async def main():
client = Client(token=TOKEN)
user_manager = UserManager(client=client)
try:
user_ids = UsersSpendingListRequest(
user_ids=[
'26e8...3f62',
'5758...0ede',
],
)
response_archive = await user_manager.spending.list(user_ids=user_ids)
...
except errors.ValidationError as e:
return str(e.args)
except errors.ApiError as e:
return e
asyncio.run(main())